import { storeAll } from "@/store";
import { routerPath } from "@/utils/contants";
import { message } from "antd";
import { observer } from "mobx-react-lite";
import React, { useEffect } from "react";
import { Outlet, useLocation, useNavigate } from "react-router-dom";

const MyoutLet: React.FC = () => {
	const navitage = useNavigate()
	const location = useLocation()
	const { adminStore: { adminInfo: { role } } } = storeAll
	useEffect(() => {
		if (!window.localStorage.getItem('graduation_yzh_token')) {
			message.warning('身份失效')
			navitage('/')
		}
	})
	useEffect(() => {
		if (role === 2 && location.pathname === '/homepage') {
			navitage('/homepage/repairList')
		}
		if (role !== 2 && location.pathname === '/homepage') {
			navitage('/homepage/introduce')
		}
		if (location.pathname === '/homepage') return
		const path = routerPath.indexOf(location.pathname.split('/')?.pop() as string)
		if (role === 0 && path < 18) {
		} else if (role === 1 && (path >= 18 && path <= 20)) {
		} else if (role === 2 && path === 21) {
		} else if (role !== 2 && path === 0) {
		} else {
			return navitage(-1)
		}
	}, [location.pathname, navitage, role])
	return <Outlet></Outlet>
}

export default observer(MyoutLet)